import cv2
import numpy as np
img = cv2.imread('demo.jpg')
conners = np.array([[873,1322],[1973,1864],[2645,3152],[857,2568]], dtype = "float32") #矩形(比如:书)的顶点 tl,tr,br,bl
canvas = np.array([[0,0],[500,0],[500,500],[0,500]], dtype = "float32") #输出文件的大小
M = cv2.getPerspectiveTransform(conners,canvas)
result = cv2.warpPerspective(img,M,(0,0))
cv2.imshow("img", result)
cv2.waitKey(0)